import axios from "axios";
// 后台服务地址
const service_url = `http://localhost:3000`;
// const service_url = `http://47.92.204.130:3000`;

// 接口: 获取轮播图列表
export const bannerListFn = (data = {}) => {
    return axios.get(`${service_url}/api/banner/list`, { params: data }).then(response => response.data)
}

// 导航列表
export const listClassifyFn = (data = {}) => {
    return axios.get(`${service_url}/api/classify/list`, { params: data }).then(response => response.data)
}


// 文章列表
export const listArticleFn = (data = {}) => {
    return axios.get(`${service_url}/api/article/items`, { params: data }).then(response => response.data)
}

// 导航子分类列表
export const listClassifyChildFn = (data = {}) => {
    return axios.get(`${service_url}/api/classify/list_child`, { params: data }).then(response => response.data)
}


// 获取文章详情
export const articleDetailFn = (data = {}) => {
    return axios.get(`${service_url}/api/article/detail`, { params: data }).then(response => response.data)
}

// 获取热门文章
export const hotArticleItemFn = (data = {}) => {
    return axios.get(`${service_url}/api/article/hot_items`, { params: data }).then(response => response.data)
}

// 判断用户是否登录
// 写代码：要合理，要有依据， 在内心要问一下：为什么写行代码？ 写这个关键字。
// ajax + promise 
export const  isLoginFn = (data={}) => {
    return axios.post(`${service_url}/api/user/isLogin`, data).then(response => response.data)
}

// 用户登录
export const loginFn = (data = {}) => {
    return axios.post(`${service_url}/api/user/login`, data).then(response => response.data)
}

// 用户注册
export const registerFn = (data = {}) => {
    return axios.post(`${service_url}/api/user/register`, data).then(response => response.data)
}

// 发送验证码
export const sendEmailCodeFn = (data = {}) => {
    return axios.get(`${service_url}/api/email/send`, {params: data}).then(response => response.data)
}

// 图片上传
export const uploadPhotoFn = (data = {}) => {
    return axios.post(`${service_url}/api/photo/preview`, data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }).then(response => response.data)
}

// 设置用户头像
export const modifyUserSrcFn = (data = {}) => {
    return axios.post(`${service_url}/api/user/modify_user_src`, data).then(response => response.data)
}

// 设置用户头像
export const getUserInfoFn = (data = {}) => {
    return axios.post(`${service_url}/api/user/info`, data).then(response => response.data)
}

// 设置用户资料
export const modifyUserInfoFn = (data = {}) => {
    return axios.post(`${service_url}/api/user/modify`, data).then(response => response.data)
}

// 删除图片
export const removePhotoFn = (data = {}) => {
    return axios.post(`${service_url}/api/photo/remove`, data).then(response => response.data)
}

//收藏文章
export const addCollectFn = (data = {}) => {
    return axios.post(`${service_url}/api/collect/add`, data).then(response => response.data)
}
// 取消收藏 
export const removeCollectFn = (data = {}) => {
    return axios.post(`${service_url}/api/collect/remove`, data).then(response => response.data)
}

// 收藏列表 
export const listCollectFn = (data = {}) => {
    return axios.get(`${service_url}/api/collect/list`, {params: data}).then(response => response.data)
}
// 发表评论
export const addCommentFn = (data = {}) => {
    return axios.post(`${service_url}/api/comment/add`, data).then(response => response.data)
}
// 删除评论
export const removeCommentFn = (data = {}) => {
    return axios.post(`${service_url}/api/comment/remove`, data).then(response => response.data)
}

// 获取评论列表
export const listCommentFn = (data = {}) => {
    return axios.get(`${service_url}/api/comment/list`, {params: data}).then(response => response.data)
}

// 回复
export const addReplyFn = (data = {}) => {
    return axios.post(`${service_url}/api/reply/add`, data).then(response => response.data)
}

// 删除回复
export const removeReplyFn = (data = {}) => {
    return axios.post(`${service_url}/api/reply/remove`, data).then(response => response.data)
}
// 回复列表
export const listReplytFn = (data = {}) => {
    return axios.get(`${service_url}/api/reply/list`, {params: data}).then(response => response.data)
}
// 根据id获取用户信息
export const userInfoFn = (data = {}) => {
    return axios.post(`${service_url}/api/user/user_info`, data).then(response => response.data)
}

// 获取收藏列表
export const listCollecttFn = (data = {}) => {
    return axios.get(`${service_url}/api/collect/list`, {params: data}).then(response => response.data)
}
// 取消收藏
export const removeCollecttFn = (data = {}) => {
    return axios.get(`${service_url}/api/collect/remove`, {params: data}).then(response => response.data)
}

// 获取分类列表
export const articleListFn = (data = {}) => {
    return axios.get(`${service_url}/api/article/list`, {params: data}).then(response => response.data)
}

// 获取收藏列表
export const collectListFn = (data = {}) => {
    return axios.get(`${service_url}/api/collect/list`, {params: data}).then(response => response.data)
}

// 搜索文章列表
export const articleSearchFn = (data = {}) => {
    return axios.get(`${service_url}/api/article/search`, {params: data}).then(response => response.data)
}

// 点击签到
export const signinAddFn = (data = {}) => {
    return axios.post(`${service_url}/api/signin/add`, data).then(response => response.data)
}

// 获取签到列表
export const signinListFn = (data = {}) => {
    return axios.get(`${service_url}/api/signin/list`, {params: data}).then(response => response.data)
}
